package aures.plugins;

import org.python.core.Py;
import org.python.core.PyException;
import org.python.core.PyFunction;
import org.python.util.PythonInterpreter;


public class Plugin {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String name;
	private String desc;
	private String filename;
	private PyFunction init;
	private PyFunction cleanup;
	private PythonInterpreter interp;
	
	public Plugin (String filename) throws Exception{

		this.filename = filename;
		this.interp = new PythonInterpreter();
		this.interp.execfile(filename);
			
		this.name = this.interp.get("__PLUGIN_NAME__").toString();
		this.desc = this.interp.get("__PLUGIN_DESC__").toString();
		this.init = (PyFunction) interp.get("aures_init");
		this.cleanup = (PyFunction) interp.get("aures_clean");

	}
	
	public PyFunction getPyFunction (String name){
		return (PyFunction) (this.interp.get(name));
	}
	
	public void init () throws Exception{
		this.init.__call__(Py.java2py(this));
	}
	
	public void clean() throws Exception{
		this.cleanup.__call__();
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public PyFunction getInit() {
		return init;
	}
	public void setInit(PyFunction init) {
		this.init = init;
	}
	public PyFunction getCleanup() {
		return cleanup;
	}
	public void setCleanup(PyFunction cleanup) {
		this.cleanup = cleanup;
	}

	public String getFilename() {
		return filename;
	}

	public PythonInterpreter getInterp() {
		return interp;
	}
}
